package cc.rengu.igas.bsps.core.service.trans;


import cc.rengu.igas.bsps.common.constant.BspsAppParamConstant;
import cc.rengu.igas.bsps.common.constant.BspsTreeNodeConstant;
import cc.rengu.igas.bsps.common.dao.BspsMchntBaseInfoMapper;
import cc.rengu.igas.bsps.common.dao.BspsMchntBindInfoMapper;
import cc.rengu.igas.bsps.common.dao.BspsPlatformMchntInfoMapper;
import cc.rengu.igas.bsps.common.dao.TradeDetailInfoMapper;
import cc.rengu.igas.bsps.common.dao.impl.BspsMchntBaseInfoMapperImpl;
import cc.rengu.igas.bsps.common.dao.impl.BspsMchntBindInfoMapperImpl;
import cc.rengu.igas.bsps.common.dao.impl.BspsPlatformMchntInfoMapperImpl;
import cc.rengu.igas.bsps.common.dao.impl.TradeDetailInfoMapperImpl;
import cc.rengu.igas.bsps.common.entity.MchntBaseInfo;
import cc.rengu.igas.bsps.common.entity.MchntBindInfo;
import cc.rengu.igas.bsps.common.entity.PlatformMchntInfo;
import cc.rengu.igas.bsps.common.enums.LimitAcctTypeEnum;
import cc.rengu.igas.bsps.common.enums.MchntTypeEnum;
import cc.rengu.igas.bsps.common.enums.OrderStateEnum;
import cc.rengu.igas.bsps.common.enums.RespCodeEnum;
import cc.rengu.igas.bsps.common.util.CSVFileUtil;
import cc.rengu.igas.bsps.core.service.base.ManageService;
import cc.rengu.igas.bsps.facade.bean.TransDetailInfoBean;
import cc.rengu.igas.bsps.facade.bean.TransSumInfoBean;
import cc.rengu.igas.bsps.facade.request.TransDetailDownloadRequest;
import cc.rengu.igas.bsps.facade.response.TransDetailDownloadResponse;
import cc.rengu.igas.share.core.model.GroupMchntInfo;
import cc.rengu.igas.share.core.realize.MchntService;
import cc.rengu.igas.share.core.realize.impl.MchntServiceImpl;
import cc.rengu.oltp.service.common.constant.AppParamConstant;
import cc.rengu.oltp.service.common.dao.UserOrderInfoMapper;
import cc.rengu.oltp.service.common.dao.impl.UserOrderInfoMapperImpl;
import cc.rengu.oltp.service.common.entity.MchntOrderInfo;
import cc.rengu.oltp.service.common.entity.PayOrderInfo;
import cc.rengu.oltp.service.common.entity.SysParam;
import cc.rengu.oltp.service.common.entity.UserOrderInfo;
import cc.rengu.oltp.service.common.enums.PayTypeEnum;
import cc.rengu.oltp.service.model.BizException;
import cc.rengu.oltp.service.model.BizResponse;
import cc.rengu.oltp.service.realize.SysParamService;
import cc.rengu.oltp.service.realize.impl.SysParamServiceImpl;
import cc.rengu.oltp.utility.bean.PageInfo;
import cc.rengu.oltp.utility.util.*;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.codec.binary.Base64;
import org.springframework.util.CollectionUtils;

import java.io.File;
import java.io.FileInputStream;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 交易明细查询下载
 * Created by Dongjk
 */
public class TransDetailDownloadService extends ManageService {
    @Override
    protected Object bizBeforeCust() throws Exception {
        TransDetailDownloadRequest transDetailDownloadRequest = new TransDetailDownloadRequest();
        ConvertUtil.convertOutput(transDetailDownloadRequest);
        return transDetailDownloadRequest;
    }

    @Override
    protected BizResponse bizProcessCust(Object request) throws Exception {
        TransDetailDownloadRequest transDetailDownloadRequest = (TransDetailDownloadRequest) request;
        TransDetailDownloadResponse transDetailDownloadResponse = new TransDetailDownloadResponse();

        BeanUtil.beanCopy(transDetailDownloadRequest, transDetailDownloadResponse);

        TradeDetailInfoMapper tradeDetailInfoMapper = new TradeDetailInfoMapperImpl();
        String mchntType = transDetailDownloadRequest.getQueryType();
        String instId = transDetailDownloadRequest.getHeader().getInstId();
        String userId = transDetailDownloadRequest.getUserId();
        String mchntNo = transDetailDownloadRequest.getMchntNo();
        String cashierId = transDetailDownloadRequest.getCashierId();


        //普通商户
        if (StringUtil.isEmptyOrNull(mchntType) || "00".equals(mchntType)) {
            //查询当前用户身份
            BspsMchntBindInfoMapper bspsMchntBindInfoMapper = new BspsMchntBindInfoMapperImpl();
            MchntBindInfo mchntBindInfo = bspsMchntBindInfoMapper.selectBspsMchntBindInfoListByUserIdAndMchntNo(instId, userId, mchntNo);
            if (mchntBindInfo == null) {
                rglog.error("用户绑定商户信息查询失败！");
                throw new BizException(RespCodeEnum.USER_MCHNT_BIND_INFO_ERROR.getRespCode(), RespCodeEnum.USER_MCHNT_BIND_INFO_ERROR.getRespDesc());
            } else {
                //角色是收银员时
                if ("02".equals(mchntBindInfo.getBindUserRole())) {
                    String remark1 = mchntBindInfo.getRemark1();
                    if (StringUtil.isEmptyOrNull(remark1)) { //没有设置
                        cashierId = userId;
                    } else {
                        Map<String, Object> reqMap = JSONObject.parseObject(remark1);
                        if (reqMap != null && reqMap.get("adminAuth") != null && !"".equals(reqMap.get("adminAuth"))) {
                            String transInfoQueryAuth = String.valueOf(reqMap.get("adminAuth"));
                            //判断是否拥有查询全部的权限
                            if ("Y".equals(transInfoQueryAuth)) {
                                cashierId = "";
                            } else {
                                cashierId = userId;
                            }
                        } else {
                            cashierId = userId;
                        }

                    }

                }
            }
        }

        //支付类型
        String startDate = transDetailDownloadRequest.getStartDate();
        String endDate = transDetailDownloadRequest.getEndDate();
        String payType = transDetailDownloadRequest.getPayType();
        String devRiskInfo = transDetailDownloadRequest.getDevRiskInfo();
        String minAmt = transDetailDownloadRequest.getMinAmt();
        String maxAmt = transDetailDownloadRequest.getMaxAmt();
        String mchntOrderId = transDetailDownloadRequest.getMchntOrderId();
        String transType = transDetailDownloadRequest.getTxnNum();
        String queryId = transDetailDownloadRequest.getQueryId();
        if (StringUtil.isEmptyOrNull(startDate) || StringUtil.isEmptyOrNull(endDate) || StringUtil.isEmptyOrNull(mchntNo)) {
            rglog.error("必填性校验失败！");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }

        String offsetDate = DateUtil.getBaseDateOffsetMonth(startDate, 1);
        if (Long.valueOf(offsetDate) < Long.valueOf(endDate)) {
            rglog.error("时间段时间不能高于一个月！");
            throw new BizException(RespCodeEnum.DATESPAN_CHECK_ERROR.getRespCode(), RespCodeEnum.DATESPAN_CHECK_ERROR.getRespDesc());
        }

        List<String> list = new ArrayList<>();
        /**查询商户信息*/
        BspsMchntBaseInfoMapper mchntBaseInfoMapper = new BspsMchntBaseInfoMapperImpl();
        //平台商户
        if ("20".equals(mchntType)) {
            /**查询平台商户*/
            BspsPlatformMchntInfoMapper platMchntInfoMapper = new BspsPlatformMchntInfoMapperImpl();
            PlatformMchntInfo platformMchntInfo = platMchntInfoMapper.selectBspsPlatformMchntInfoByInstIdAndMchntNo(instId, mchntNo);
            if (platformMchntInfo == null) {
                rglog.info("获取商户信息失败！");
                throw new BizException(RespCodeEnum.MCHNT_INFO_NOT_FOUND.getRespCode(), RespCodeEnum.MCHNT_INFO_NOT_FOUND.getRespDesc());
            }
            transDetailDownloadResponse.setMchntNo(platformMchntInfo.getPlatMchntNo());
            transDetailDownloadResponse.setMchntName(platformMchntInfo.getPlatMchntName());
            //集团商户
        } else if ("10".equals(mchntType)) {
            MchntService mchntService = new MchntServiceImpl();
            GroupMchntInfo groupMchntInfo = mchntService.getGroupMchntInfo(instId, mchntNo);
            if (groupMchntInfo == null) {
                rglog.info("获取商户信息失败！");
                throw new BizException(RespCodeEnum.MCHNT_INFO_NOT_FOUND.getRespCode(), RespCodeEnum.MCHNT_INFO_NOT_FOUND.getRespDesc());
            }
            transDetailDownloadResponse.setMchntNo(groupMchntInfo.getGroupMchntNo());
            transDetailDownloadResponse.setMchntName(groupMchntInfo.getGroupMchntName());
        } else {
            MchntBaseInfo mchntBaseInfo = mchntBaseInfoMapper.selectBspsMchntBaseInfoByPrimaryKey(instId, mchntNo);
            if (mchntBaseInfo == null) {
                rglog.info("获取商户信息失败！");
                throw new BizException(RespCodeEnum.MCHNT_INFO_NOT_FOUND.getRespCode(), RespCodeEnum.MCHNT_INFO_NOT_FOUND.getRespDesc());
            }

            if ("10".equals(mchntBaseInfo.getMchntType())) { //连锁商户
                mchntType = "30";
            } else { //普通商户或门店
                mchntType = "00";
            }
            transDetailDownloadResponse.setMchntNo(mchntBaseInfo.getMchntNo());
            transDetailDownloadResponse.setMchntName(mchntBaseInfo.getMchntName());
            transDetailDownloadResponse.setMchntType(mchntBaseInfo.getMchntType());
        }

        if (StringUtil.isEmptyOrNull(mchntNo)) {
            rglog.info("没有查询到相关的商户信息！");
            throw new BizException(RespCodeEnum.MCHNT_INFO_NOT_FOUND.getRespCode(), RespCodeEnum.MCHNT_INFO_NOT_FOUND.getRespDesc());
        }

        List<MchntOrderInfo> mchntOrderInfolist = null;
        List<MchntOrderInfo> mchntOrderInfolistRun = null;

        //查询汇总
        List<TransSumInfoBean> transSumInfoBeans = new ArrayList<>();
        if ("P01".equals(transType) || StringUtil.isEmptyOrNull(transType)) {
            mchntOrderInfolist = tradeDetailInfoMapper.selectMchntOrderGroupByDate(instId, mchntNo, startDate, endDate, cashierId, "P01", payType, null, minAmt, maxAmt, mchntOrderId, mchntType, queryId);
        }
        if ("P04".equals(transType) || StringUtil.isEmptyOrNull(transType)) {
            mchntOrderInfolistRun = tradeDetailInfoMapper.selectMchntOrderGroupByDate(instId, mchntNo, startDate, endDate, cashierId, "P04", payType, null, minAmt, maxAmt, mchntOrderId, mchntType, queryId);
        }


        /**时间段*/
        List<String> dateslist = findDates(startDate, endDate);
        List<TransSumInfoBean> transSumInfoList = new ArrayList<>();
        String sumTransAmt = "0";
        for (int i = 0; i < dateslist.size(); i++) {
            TransSumInfoBean transSumInfoBean = new TransSumInfoBean();
            String date = dateslist.get(i);
            String transAmt = "0";
            String transNum = "0";
            String transAmtRun = "0";
            String transNumRun = "0";
            if ((mchntOrderInfolist == null || mchntOrderInfolist.size() == 0) && (mchntOrderInfolistRun == null || mchntOrderInfolistRun.size() == 0)) {
                transSumInfoBean.setTxnDate(date);
                transSumInfoBean.setTransNum("0");
                transSumInfoBean.setTransAmt("0");
                transSumInfoList.add(transSumInfoBean);
                rglog.info(date + "数据为0条!");
            } else {
                if (mchntOrderInfolist != null && mchntOrderInfolist.size() != 0) {

                    //查看当天是否有正向交易数据
                    List<MchntOrderInfo> mchntOrderList = mchntOrderInfolist.stream().filter(item -> date.equals(item.getTxnDate())).collect(Collectors.toList());
                    boolean mchntOrderListIsnull = (mchntOrderList == null || mchntOrderList.size() == 0);
                    transAmt = mchntOrderListIsnull ? "0" : mchntOrderList.get(0).getRemark1();
                    transNum = mchntOrderListIsnull ? "0" : mchntOrderList.get(0).getRemark2();
                }
                if (mchntOrderInfolistRun != null && mchntOrderInfolistRun.size() != 0) {

                    //查看当天是否有退款交易
                    List<MchntOrderInfo> mchntOrderListRun = mchntOrderInfolistRun.stream().filter(item -> date.equals(item.getTxnDate())).collect(Collectors.toList());
                    boolean mchntOrderListRunIsnull = (mchntOrderListRun == null || mchntOrderListRun.size() == 0);
                    transAmtRun = mchntOrderListRunIsnull ? "0" : mchntOrderListRun.get(0).getRemark1();
                    transNumRun = mchntOrderListRunIsnull ? "0" : mchntOrderListRun.get(0).getRemark2();
                }

                /**计算出当天的总数量与总交易值*/
                BigDecimal transAmtDecimal = new BigDecimal(transAmt);
                BigDecimal transAmtDecimalb = new BigDecimal(transAmtRun);
                String dateTransAmt = transAmtDecimal.subtract(transAmtDecimalb).toString();

                BigDecimal transNumDecimal = new BigDecimal(transNum);
                BigDecimal transNumRunDecimalb = new BigDecimal(transNumRun);
                String dateTransNum = transNumDecimal.add(transNumRunDecimalb).toString();

                /**计算总金额*/

                BigDecimal transNumDecimalc = new BigDecimal(sumTransAmt);
                BigDecimal transNumRunDecimald = new BigDecimal(dateTransAmt);
                sumTransAmt = transNumDecimalc.add(transNumRunDecimald).toString();

                transSumInfoBean.setTxnDate(date);
                transSumInfoBean.setTransNum(dateTransNum);
                transSumInfoBean.setTransAmt(dateTransAmt);
                transSumInfoList.add(transSumInfoBean);

            }
        }


        /*查询交易数据*/
        PageInfo pageInfo = new PageInfo();
        pageInfo.setPageIndex(transDetailDownloadRequest.getPageIndex());
        pageInfo.setPageSize(transDetailDownloadRequest.getPageSize());
        String state = null;
        List<MchntOrderInfo> pageResult = tradeDetailInfoMapper.selectPayOrderDownload(instId, mchntNo, startDate, endDate, cashierId, payType, minAmt, maxAmt, mchntOrderId, transType, state, mchntType, queryId);
        List<String> dataList = new ArrayList<>();
        dataList.add("交易总金额:," + sumTransAmt.concat("\t") + "");
        dataList.add("商户订单号,一级商户,二级商户名称（终端）,二级商户号（终端）,交易时间,借贷记标记,交易状态,交易渠道,交易金额(元),手续费(元),是否退货,收银员,备注,卡号");
        if (pageResult == null) {
            rglog.info("根据查询条件，数据为0条!");
        } else {
            List<TransDetailInfoBean> transDetailInfoBeanList = new ArrayList<>();
            for (Object object : pageResult) {
                MchntOrderInfo mchntOrderInfo = (MchntOrderInfo) object;
                TransDetailInfoBean transDetailInfoBean = new TransDetailInfoBean();
                //查询支付订单表
                PayOrderInfo payOrderInfo = new PayOrderInfo();
                List<PayOrderInfo> payOrderInfoList = tradeDetailInfoMapper.bspsSelectPayOrderInfoBySysSeqNum(instId, mchntOrderInfo.getSysSeqNum());
                if (!CollectionUtils.isEmpty(payOrderInfoList)) {
                    payOrderInfoList = payOrderInfoList.stream().filter(item -> ((!"0007".equals(item.getChannelBizType()) && !"0014".equals(item.getChannelBizType())))).collect(Collectors.toList());
                    if (!CollectionUtils.isEmpty(payOrderInfoList)) {
                        payOrderInfo = payOrderInfoList.get(0);
                        //支付类型
                        String orderPayType = payOrderInfo.getPayType();
                        //支付方信息
                        String payerAcctInfo = payOrderInfo.getPayerAcctInfo();
                        if (!StringUtil.isEmptyOrNull(payerAcctInfo)) {
                            if ("00".equals(orderPayType) || "01".equals(orderPayType) || "04".equals(orderPayType)) {
                                //支付方式为银行卡的进行掩码
                                if (!StringUtil.isEmptyOrNull(payerAcctInfo)) {
                                    payOrderInfo.setPayerAcctInfo(subStr(payerAcctInfo, 6, payerAcctInfo.length() - 4));
                                    rglog.debug("查询对应的付款账号<{}>", payOrderInfo.getPayerAcctInfo());
                                }
                            }
                        }
                        transDetailInfoBean.setPayType(orderPayType);
                        transDetailInfoBean.setPayerAcctType(payOrderInfo.getPayerAcctType());
                        transDetailInfoBean.setPayerAcctInfo(payOrderInfo.getPayerAcctInfo());
                    }
                }

                UserOrderInfoMapper userOrderInfoMapper = new UserOrderInfoMapperImpl();
                UserOrderInfo userOrderInfo = userOrderInfoMapper.selectUserOrderInfoByPrimaryKey(mchntOrderInfo.getInstId(), mchntOrderInfo.getSysSeqNum());

                /**查询商户信息*/
                MchntBaseInfo mchntBaseInfo = mchntBaseInfoMapper.selectBspsMchntBaseInfoByPrimaryKey(mchntOrderInfo.getInstId(), mchntOrderInfo.getMchntNo());
                if (mchntBaseInfo != null) {
                    transDetailInfoBean.setMchntNo(mchntBaseInfo.getMchntNo());
                    transDetailInfoBean.setMchntName(mchntBaseInfo.getMchntName());
                    transDetailInfoBean.setMchntType(mchntBaseInfo.getMchntType());
                }

                MchntBaseInfo chainMchnt = mchntBaseInfoMapper.selectBspsMchntBaseInfoByPrimaryKey(mchntOrderInfo.getInstId(), mchntOrderInfo.getUpdateTime());

                String mchntOrderIdb = mchntOrderInfo.getMchntOrderId();
                transDetailInfoBeanList.add(transDetailInfoBean);
                StringBuffer stringBuffer = new StringBuffer();
                stringBuffer.append(mchntOrderIdb.concat("\t"));
                stringBuffer.append(",");
                //一级商户名称
                if (MchntTypeEnum.CHAIN_MCHNT.getMchntType().equals(mchntBaseInfo.getMchntType())) {
                    stringBuffer.append(StringUtil.isEmptyOrNull(mchntBaseInfo.getMchntName()) ? "" : mchntBaseInfo.getMchntName());
                } else {
                    if (chainMchnt == null) {
                        stringBuffer.append("");
                    } else {
                        stringBuffer.append(StringUtil.isEmptyOrNull(chainMchnt.getMchntName()) ? "" : chainMchnt.getMchntName());
                    }
                }

                stringBuffer.append(",");
                /**商户是连锁商户*/
                if (MchntTypeEnum.CHAIN_MCHNT.getMchntType().equals(mchntBaseInfo.getMchntType())) {
                    //二级商户名称
                    stringBuffer.append("");
                    stringBuffer.append(",");
                    //二级商户号
                    stringBuffer.append("");
                } else {
                    //二级商户名称
                    stringBuffer.append(mchntBaseInfo.getMchntName());
                    stringBuffer.append(",");
                    //二级商户号
                    stringBuffer.append(mchntOrderInfo.getMchntNo().concat("\t"));
                }

                stringBuffer.append(",");
                stringBuffer.append(mchntOrderInfo.getCreateTime().concat("\t"));
                stringBuffer.append(",");
                //借贷记标记
                String payerAcctType = LimitAcctTypeEnum.getLimitAcctTypeDesc(transDetailInfoBean.getPayerAcctType());
                stringBuffer.append(payerAcctType == null ? "" : payerAcctType);

                stringBuffer.append(",");
                //交易状态
                String orderStateEnum = OrderStateEnum.getStatesDesc(mchntOrderInfo.getTransStatus());
                stringBuffer.append(orderStateEnum);
                stringBuffer.append(",");
                //交易渠道
                String orderPayTypeDesc = PayTypeEnum.getPayTypeDesc(transDetailInfoBean.getPayType());
                stringBuffer.append(StringUtil.isEmptyOrNull(orderPayTypeDesc) ? "" : orderPayTypeDesc);
                stringBuffer.append(",");
                stringBuffer.append(mchntOrderInfo.getOrderAmt().concat("\t"));
                stringBuffer.append(",");
                stringBuffer.append(StringUtil.isEmptyOrNull(payOrderInfo.getCustomerFee()) ? "" : payOrderInfo.getCustomerFee().concat("\t"));
                stringBuffer.append(",");
                String bizType = mchntOrderInfo.getBizType();
                if ("30".equals(bizType) || "31".equals(bizType) || "32".equals(bizType) || "33".equals(bizType)) {
                    stringBuffer.append("是");
                } else {
                    stringBuffer.append("否");
                }

                stringBuffer.append(",");
                stringBuffer.append(StringUtil.isEmptyOrNull(payOrderInfo.getPayeeRemark()) ? "" : payOrderInfo.getPayeeRemark());
                stringBuffer.append(",");
                if (null != userOrderInfo) {
                    stringBuffer.append(StringUtil.isEmptyOrNull(userOrderInfo.getOrderDesc()) ? "" : userOrderInfo.getOrderDesc());
                } else {
                    stringBuffer.append("");
                }
                stringBuffer.append(",");
                stringBuffer.append(StringUtil.isEmptyOrNull(transDetailInfoBean.getPayerAcctInfo()) ? "" : transDetailInfoBean.getPayerAcctInfo().concat("\t"));
                dataList.add(stringBuffer.toString());

            }
        }

        SysParamService sysParamService = new SysParamServiceImpl();
        SysParam sysParam = sysParamService.getSysParamInfo(AppParamConstant.DEFAULT_INSTID, BspsAppParamConstant.FILE_PATH_PARAM, BspsAppParamConstant.TRANS_DETAIL_DOWNLOAD);
        if (sysParam == null) {
            rglog.info("文件存储路径未配置");
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }
        String filePath = sysParam.getParamValue().concat("/").concat(instId).concat("/").concat(DateUtil.getCurrentDateTime("yyyyMMdd")).concat("/");
        String name = transDetailDownloadResponse.getMchntNo().concat("_").concat(DateUtil.getCurrentDateTime("yyyyMMddHHmmss")).concat(".csv");
        CSVFileUtil.exportCSV(filePath.concat(name), dataList);
        rglog.debug("================目录" + filePath);
        rglog.debug("================欲下载名称" + name);
        File reconFile = new File(filePath.concat(name));
        if (!reconFile.exists()) {
            rglog.error("目录不存在.");
            throw new BizException(RespCodeEnum.FILE_NOT_EXIST.getRespCode(), RespCodeEnum.FILE_NOT_EXIST.getRespDesc());
        }
        byte[] fileBytes = null;
        String flieName = null;
        FileInputStream fileInputStream = null;
        fileInputStream = new FileInputStream(reconFile);
        fileBytes = new byte[fileInputStream.available()];
        fileInputStream.read(fileBytes);
        fileBytes.clone();
        fileInputStream.close();
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();

        if (null != fileBytes) {
            transDetailDownloadResponse.setFileContent(Base64.encodeBase64String(fileBytes));
        }
        /* 按照接口转换基础产品信息并响应给请求方 */
        BizResponse bizResponse = new BizResponse();
        bizResponse.setRspSysId(AppParamConstant.SYS_ID);
        bizResponse.setRespCode(RespCodeEnum.TRANS_SUCCESS.getRespCode());
        bizResponse.setRespDesc(RespCodeEnum.TRANS_SUCCESS.getRespDesc());
        if ("Y".equals(xmlTreeUtil.getXmlTreeStringValue(BspsTreeNodeConstant.IS_GET_REQUEST))) {
            xmlTreeUtil.setXmlTreeStringValue(BspsTreeNodeConstant.RECON_DETAIL_PATH, filePath.concat(name));
            return bizResponse;
        }

        bizResponse.setResult(transDetailDownloadResponse);
        return bizResponse;
    }

    @Override
    protected void bizAfterCust(Object response) throws Exception {
        BizResponse bizResponse = (BizResponse) response;
        TransDetailDownloadResponse transDetailDownloadResponse = (TransDetailDownloadResponse) bizResponse.getResult();
        ConvertUtil.convertInput(transDetailDownloadResponse);
    }

    /**
     * 将数据库表结构对象转换成接口对象
     */
    private void convGroupMchntInfo(TransSumInfoBean transSumInfoBean, List<TransSumInfoBean> transSumInfoBeans) {
        TransSumInfoBean transSumInfoBean1 = new TransSumInfoBean();
        BeanUtil.beanCopy(transSumInfoBean, transSumInfoBean1);
        transSumInfoBeans.add(transSumInfoBean1);
    }

    public List<String> findDates(String stime, String etime) throws Exception {
        List<String> allDate = new ArrayList();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");

        Date dBegin = sdf.parse(stime);
        Date dEnd = sdf.parse(etime);
        allDate.add(sdf.format(dBegin));
        Calendar calBegin = Calendar.getInstance();
        // 使用给定的 Date 设置此 Calendar 的时间
        calBegin.setTime(dBegin);
        Calendar calEnd = Calendar.getInstance();
        // 使用给定的 Date 设置此 Calendar 的时间
        calEnd.setTime(dEnd);
        // 测试此日期是否在指定日期之后
        while (dEnd.after(calBegin.getTime())) {
            // 根据日历的规则，为给定的日历字段添加或减去指定的时间量
            calBegin.add(Calendar.DAY_OF_MONTH, 1);
            allDate.add(sdf.format(calBegin.getTime()));
            Thread.sleep(100);
        }
        return allDate;
    }

    /**
     * 字符串截取
     *
     * @param sourceStr 待脱敏串
     * @param begin     开始位置
     * @param end       结束位置
     * @return 脱敏串
     */
    private static String subStr(String sourceStr, int begin, int end) {
        if (StringUtil.isEmptyOrNull(sourceStr) || begin > end) {
            return "";
        }
        if (begin == end) {
            return sourceStr.replaceFirst(sourceStr.substring(begin), "*");
        }
        StringBuffer stringBuffer = new StringBuffer(sourceStr.substring(0, begin));
        for (int index = begin; index < end; index++) {
            stringBuffer.append("*");
        }
        stringBuffer.append(sourceStr.substring(end));
        return stringBuffer.toString();
    }


}

